home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / go4gw1.1 / g2geo < prev    next >
Encoding:
Text File  |  1993-04-30  |  2.8 KB  |  153 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # variables you should change:
  5.  
  6. $geo_server    = "geoserver.eecs.umich.edu";
  7. $geo_port      = 3000;
  8.  
  9. #----------------------------------------------------------------------
  10.  
  11. # gateway from gopher to the geographic name server
  12. # this is the "brute force" kind of approach; a tidier solution
  13. # would speak the prospero protocols directly.
  14.  
  15. sub geo_main {
  16.     
  17.     local($_) = @_;
  18.     
  19.     if (/^$/) {
  20.     &Greply("7Search Geographic Name Server by City or ZIP code\t$Ggw search\t$Ghost\t$Gport");
  21.     &Greply(".");
  22.     exit;
  23.     }
  24.     
  25.     ($action, $query, $gplus) = split('\t');
  26.  
  27.     if ($action =~ /^city/) {
  28.     $city = $action;
  29.     $city =~ s/^city//;
  30.     &GopenServer($geo_server, $geo_port);
  31.  
  32.     # remove banner
  33.     while ($_ ne ".") {
  34.         $_ = &Grecv;
  35.     }
  36.     &Gsend($city);
  37.  
  38.     $_ = "";
  39.  
  40.       LOOP:
  41.     while ($_ ne "." || $_ eq "") {
  42.  
  43.         $_ = &Grecv;
  44.         
  45.         s/^R /Note            : /;
  46.         s/^0 /City            : /;
  47.         if (/^1 /) {
  48.         s/^1 //;
  49.         s/(\d+)/[$1]/;
  50.         push(@Counties,$_);
  51.         next LOOP;
  52.             }
  53.         s/^3 /Nation          : /;
  54.         s/^A /Area-Code       : /;
  55.         s/^2 /State\/Province  : /;
  56.         s/^F /Feature Code    : /;
  57.  
  58.         if (/^E /) {
  59.             s/^E /Elevation       : /;
  60.         $_ = $_ . " feet";
  61.         }
  62.         if (/^L /) {
  63.         ($L, $latdeg, $latmin, $latsec, $NS,
  64.              $londeg, $lonmin, $lonsec, $EW) =
  65.              split;
  66.         &Greply("");
  67.             &Greply("Latitude        : $latdeg degrees, $latmin minutes, $latsec seconds $NS");
  68.         &Greply("Longitude       : $londeg degrees, $lonmin minutes, $lonsec seconds $EW");
  69.         &Greply("");
  70.         next LOOP;
  71.         }
  72.  
  73.         if (/^P /) {
  74.         s/^P /1980 Population : /;
  75.         }
  76.  
  77.         if (/^Z /) {
  78.         s/^Z //;
  79.         push(@Zips, $_);
  80.         next LOOP;
  81.         }
  82.  
  83.         &Greply($_) unless ($_ eq "." || $_ eq "");
  84.     }
  85.  
  86.     &Greply("");
  87.     $line = "ZIP Codes       : ";
  88.     foreach $i (@Zips) {
  89.         if (length($line) <70) {
  90.         $line = "$line $i";
  91.         } else {
  92.         &Greply($line);
  93.         $line = "                : ";
  94.         }
  95.     }
  96.     &Greply($line);
  97.  
  98.     &Greply("");
  99.     $line = "Counties        : ";
  100.     foreach $i (@Counties) {
  101.         if (length($line) <70) {
  102.         $line = "$line $i";
  103.         } else {
  104.         &Greply($line);
  105.         $line = "                : ";
  106.         }
  107.     }
  108.  
  109.     &Greply($line);
  110.  
  111.     if ($_ eq "") {
  112.         @Zips = ();
  113.         @Counties = ();
  114.         &Greply("");
  115.         next LOOP;
  116.     }
  117.     }
  118.  
  119.  
  120.  
  121.     elsif ($action eq "search") {
  122.     &GopenServer($geo_server,$geo_port);
  123.     # remove banner
  124.     while ($_ ne ".") {
  125.         $_ = &Grecv;
  126.     }
  127.     &Gsend($query);
  128.  
  129.     $_ = "";    
  130.     while ($_ ne ".") {
  131.         $_ = &Grecv;
  132.         
  133.         if (/^0 (.*)$/) {
  134.         $City = $1;
  135.         }
  136.         if (/^2 (\S+) (.*)$/) {
  137.         $States{$1} = $City;
  138.         }
  139.     }
  140.     
  141.     foreach $i (keys(%States)) {
  142.         &Greply("0$States{$i}, $i\tgeo city $States{$i}, $i\t$Ghost\t$Gport");
  143.         }
  144.     }
  145.  
  146.  
  147.     &Greply(".");
  148.     exit;
  149.     
  150. }
  151.  
  152. 1;
  153.